/**
 * Copyright 2009 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.sapien.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;

import com.google.code.sapien.dao.RoleDAO;
import com.google.code.sapien.model.Role;
import com.google.inject.Inject;

/**
 * A JPA implementation of the {@link com.google.code.sapien.dao.RoleDAO} interface.
 * @author Adam
 * @version $Id$
 * 
 * Created on May 8, 2009 at 6:14:25 PM 
 */
public class RoleJpaDAO extends AbstractJpaDAO<Role> implements RoleDAO {
	/**
	 * Constructs a role JPA data access object.
	 * @param entityManager The entity manager.
	 */
	@Inject
	public RoleJpaDAO(final EntityManager entityManager) {
		super(entityManager);
	}

	/**
	 * {@inheritDoc}
	 * @see com.google.code.sapien.dao.RoleDAO#getCount()
	 */
	public int getCount() {
		return ((Number) getEntityManager().createNamedQuery("role.getCount").getSingleResult()).intValue();
	}

	/**
	 * {@inheritDoc}
	 * @see com.google.code.sapien.dao.RoleDAO#listAll()
	 */
	@SuppressWarnings("unchecked")
	public List<Role> listAll() {
		return getEntityManager().createNamedQuery("role.listAll").getResultList();
	}

	/**
	 * {@inheritDoc}
	 * @see com.google.code.sapien.dao.RoleDAO#listForNewUsers()
	 */
	@SuppressWarnings("unchecked")
	public List<Role> listForNewUsers() {
		return getEntityManager().createNamedQuery("role.listForNewUsers").getResultList();
	}

}
